<?php

/**
 * Description of LocaleProvider
 *
 * @author prometheus
 */
class x10_LocaleProvider extends x10_Provider
{
	public $xName = 'Nyelvi szótár szolgáltató';

	public $localeFileFolder = '';

	public $localeClassName = '';
	
	public $localeFileName = '';

	public $localeFilePath = '';

	/**
	 * @var x10_LocaleManager
	 */
	protected $lcMan;

	protected $translator;

	/**
	 * Konstruktor.
	 * @param x10_Config $config
	 * @throws E_Provider_ConfigNotExists
	 * @throws E_Provider_ConfigParseError
	 */
	public function __construct(x10_Config $config)
	{
		parent::__construct($config);

		$this->lcMan = x10::dedicate('x10_LocaleManager');
		$lc = $this->config->getConfigKey('defaultLocale');

		$this->localeFileFolder = $this->config->getConfigKey('localeFileFolder');
		$this->localeClassName = $this->config->getConfigKey('localeClassName');
		$this->setLocaleFileName(isset($lc)? $lc : '');
		$this->localeFilePath = $this->localeFilePath.$this->localeFileName;
	}

	public function createTranslator($locale='')
	{
		
	}

	public function setLocaleFileName($lc='')
	{
		if (empty($lc)) $lc = $this->lcMan->getDefaultLocale();
		if (empty($this->localeClassName))
		{
			$this->localeFileName = 'locale.'.$lc.'.json';
		}
		else
		{
			$this->localeFileName = 'locale.'.$this->localeClassName.'.'.$lc.'.json';
		}
	}

	public function getLocaleFileName($lc='')
	{
		$result = $this->localeFileName;
		if (!empty($lc))
		{
			$lc = $this->lcMan->getDefaultLocale();
			if (empty($this->localeClassName))
			{
				$result = 'locale.'.$lc.'.json';
			}
			else
			{
				$result = 'locale.'.$this->localeClassName.'.'.$lc.'.json';
			}
		}
		return $result;
	}
}

?>